package com.edu.html.service.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.edu.common.model.PageQuery;
import com.edu.html.dao.BookDao;
import com.edu.html.pojo.Books;
import com.edu.html.service.BookService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service("bookService")
public class BookServiceImpl implements BookService{
	
	@Autowired
	private BookDao bookDao;

	@Override
	@Cacheable(value="systemCache", key="'book_'+ #pId")
	public Books getBook(String pId) {
		System.out.println("--是否查询缓存数据:false--"+pId);
		Books book = bookDao.getBook(Integer.parseInt(pId));
		return book;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public PageQuery<Books> queryList(Books book) {
		PageQuery<Books> pageQuery = new PageQuery<Books>();
		int pageNum = book.getPage() == null ? 1 : book.getPage();
		int pageSize = book.getRows() == null ? 10 : book.getRows();
        Page page = PageHelper.startPage(pageNum, pageSize, true);
		List<Books> books = bookDao.queryList(book);
		pageQuery.setPageNum(pageNum);
		pageQuery.setPageSize(pageSize);
		pageQuery.setRows(books);
		pageQuery.setTotal((int) page.getTotal());
		return pageQuery;
	}

}
